package com.csy.property.controller.community;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.property.community.domain.AjUnit;
import com.csy.property.community.domain.vo.RoomTree;
import com.csy.property.community.service.AjUnitService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: sunxx
 * @Date: 2024/4/22 - 04 - 22 - 18:07
 * @Description: com.sxx.ajcommunity.web.controller.community
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/unit")
public class AjUnitController extends BaseController {

    @Resource
    private AjUnitService ajUnitService;

    @GetMapping("/list")
    private PageResult list(AjUnit ajUnit){
        startPage();
        List<AjUnit> ajUnits = ajUnitService.selectUnitList(ajUnit);
        return getData(ajUnits);
    }
    @GetMapping("/{unitId}")
    private BaseResponse getById(@PathVariable("unitId") Long unitId){
        AjUnit unit = ajUnitService.getById(unitId);
        return BaseResponse.success(unit);
    }

    @PostMapping
    private BaseResponse addUnit(@RequestBody AjUnit ajUnit){
        int row = ajUnitService.add(ajUnit);
        if (row > 0){
            return BaseResponse.success(row);
        }
        return BaseResponse.fail("请输入正确的小区、楼栋等信息！");
    }
    @PutMapping
    private BaseResponse updateUnit(@RequestBody AjUnit ajUnit){

        return toAjax(ajUnitService.updateUnit(ajUnit));
    }

    @DeleteMapping("/{unitId}")
    private BaseResponse delUnit(@PathVariable("unitId") Long[] ids){

        return toAjax(ajUnitService.deleteAjUnit(ids));
    }
    @GetMapping("/queryPullDownRoom")
    public BaseResponse pullDownList(AjUnit ajUnit){

        List<RoomTree> roomTrees = ajUnitService.queryPullAreaBuildUnit(ajUnit);
//        List<RoomTree> roomTrees = ajUnitService.queryPullDownRoom(ajUnit);
        return BaseResponse.success(roomTrees);
    }
}
